program Del1andDel4;

{$APPTYPE CONSOLE}

uses
  SysUtils, ProcedureDelFromEnd;

var
  Head, temp, current: PElement;
  i, tmp: integer;
  input: TextFile;

procedure AddToEnd( head: PElement; num: integer );
var
  current: Pelement;
begin
  while current^.next <> nil do
    current := current^.Next;
  new( current^.Next );
  current^.Next^.next := nil;
  current^.next^.value := num;
end;

begin
  new( head );
  head^.Next := nil;
  AssignFile( input,'input.txt' );
  reset( input );
  while not eof( input ) do begin
    readln( input, tmp );
    AddToEnd( head, tmp );
  end;
  CloseFile( input );

  for i := 0 to 4 do begin
    temp := head^.Next;
    dispose( head );
    head := temp;
    DelFromEnd( head );
  end;


  current := head;
  while current <> nil do begin
    writeln( current^.Value );
    current := current^.Next;
  end;

  current := head;
  for i := 1 to 3 do begin
    current := current^.Next;
  end;
  //Dispose( current^.Next );
  //current^.Next := current^.Next^.Next;

  readln;
end.
